package com.burgeon.backend.Util.menu;

import com.burgeon.backend.SHOP.entity.Wechat;
import com.burgeon.backend.SHOP.mappers.WechatAppMapper;
import com.burgeon.backend.SHOPBACKEND.entity.wamenu.*;
import com.burgeon.backend.Util.wechatUtil.WeGetAccessToken;
import com.burgeon.backend.WeChat.GetAccesToken;
import com.burgeon.backend.entity.AccessToken;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 类名: MenuManager </br>
 * 描述:菜单管理器类 </br>
 */
@Service
public class MenuManager {
    private static Logger log = LoggerFactory.getLogger(MenuManager.class);
    private static WechatAppMapper wechatAppMapper;


    public static void main(String[] args) {

        // 第三方用户唯一凭证
        String appId = "你公众号的appId";
        // 第三方用户唯一凭证密钥
        String appSecret = "你公众号的appSecret";

        /**不能在这里测试**/
        // 调用接口获取access_token
        //String at = WeGetAccessToken.getAccessToken();
        String access_token = WeixinUtil.getAccessToken(WeChatInfo.WX_APPID,WeChatInfo.WX_APPSECRET).getToken();
//        GetAccesToken getAccesToken = new GetAccesToken();
//        System.err.println(WeChatInfo.token);
       // String access_token = GetAccesToken(WeChatInfo.token);
        System.err.println("获取Access_token==="+access_token);

        if (null != access_token) {
            // 调用接口创建菜单
            String result = WeixinUtil.createMenu(getMenu(), access_token);
            //String result =""; //WeixinUtil.deleteMenu(getMenu(),at);
            System.err.println("MenuManager"+result);
            // 判断菜单创建结果
            if ("0".equals(result))
                log.info("菜单创建成功！");
            else
                log.info("菜单创建失败，错误码：" + result);
        }
    }
    /**
     * 组装菜单数据
     * @return
     */
    public static Menu getMenu() {
        String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx64acb710347f7e5c&redirect_uri=http://lfwd.cloudsmicro.com/weixin/ReVip.html&response_type=code&scope=snsapi_base&state=123#wechat_redirect";

//        CommonButton btn11 = new CommonButton();
//        btn11.setName("跳转授权页面");
//        btn11.setType("view");
//        btn11.setUrl(url);
        //view按钮
        ViewButton btn21 = new ViewButton();
        btn21.setName("认证");
        btn21.setType("view");
        btn21.setUrl(url);
        System.err.println(btn21);

//        ViewButton btn22 = new ViewButton();
//        btn22.setName("官方链接");
//        btn22.setType("view");
//        btn22.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx520c15f417810387&redirect_uri=https%3A%2F%2Fchong.qq.com%2Fphp%2Findex.php%3Fd%3D%26c%3DwxAdapter%26m%3DmobileDeal%26showwxpaytitle%3D1%26vb2ctag%3D4_2030_5_1194_60&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
//
//        ViewButton btn23 = new ViewButton();
//        btn23.setName("查询");
//        btn23.setType("view");
//        btn23.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx44eb1076428bc798&redirect_uri=http://992nkr.natappfree.cc/appointment/wechat/toAppoin/oauth&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect");
//
//        ViewButton btn24 = new ViewButton();
//        btn24.setName("查询2");
//        btn24.setType("view");
//        btn24.setUrl("https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx44eb1076428bc798&redirect_uri=http%3a%2f%2fgb4xrs.natappfree.cc%2fappointment%2fwechat%2ftoAppoin%2foauth&response_type=code&scope=snsapi_base&state=123#wechat_redirect");
//
//        ViewButton btn25 = new ViewButton();
//        btn25.setName("登录");
//        btn25.setType("view");
//        btn25.setUrl("http://gb4xrs.natappfree.cc/appointment/sys/login.view");

      /*  ViewButton btn26 = new ViewButton();
        btn26.setName("测试");
        btn26.setType("view");
        btn26.setUrl("http://ytuwpp.natappfree.cc/appointment/wechat/toAppoin/toAppointInit");
        */


        CommonButton btn33 = new CommonButton();
        btn33.setName("幽默笑话");
        btn33.setType("click");
        btn33.setKey("33");


        /**
         * 微信：  mainBtn1,mainBtn2,mainBtn3底部的三个一级菜单。
         */

        ComplexButton mainBtn1 = new ComplexButton();
        mainBtn1.setName("个人中心");
        //一级下有4个子菜单
        mainBtn1.setSub_button(new ViewButton[] { btn21 });

//        ComplexButton mainBtn2 = new ComplexButton();
//        mainBtn2.setName("菜单");
//        mainBtn2.setSub_button(new ViewButton[] {btn22,btn23,btn24,btn25 });
//
//
//        ComplexButton mainBtn3 = new ComplexButton();
//        mainBtn3.setName("更多体验");
//        mainBtn3.setSub_button(new CommonButton[] {  btn33 });



        /**
         * 封装整个菜单
         */
        Menu menu = new Menu();
        menu.setButton(new Button[] { mainBtn1});//, mainBtn2, mainBtn3 });

        return menu;
    }
}